def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def closest_prime(number):
    offset = 0
    while True:
        if is_prime(number + offset):
            return number + offset
        elif is_prime(number - offset):
            return number - offset
        offset += 1

words_to_numbers = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

input_string = input("Введите три слова, обозначающие числа: ")
words = input_string.split()

if len(words) != 3 or not all(word in words_to_numbers for word in words):
    print("Wrong input")
else:
    number = 100 * words_to_numbers[words[0]] + 10 * words_to_numbers[words[1]] + words_to_numbers[words[2]]
    print(closest_prime(number))
